﻿using System;
using System.Collections.Generic;
using System.Data.Entity.ModelConfiguration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Delphi.Mimir.Data.Entities.Final.Mappings {
    public class CashTransactionMap : EntityTypeConfiguration<CashTransaction> {
        public CashTransactionMap() {
            /******************************************************************
            /* Table
            /*****************************************************************/
            ToTable("fin.pfm_cash_transactions");

            /******************************************************************
            /* Primary Key
            /*****************************************************************/
            HasKey(a => a.CashTransactionId);

            /******************************************************************
            /* Index
            /*****************************************************************/
            // none

            /******************************************************************
            /* Relationships
            /*****************************************************************/
            // 1..n Managed Product
            HasRequired<ManagedProduct>(a => a.ManagedProduct)
                .WithMany()
                .HasForeignKey(a => a.ManagedProductId);

            HasRequired<Currency>(a => a.Currency)
                .WithMany()
                .HasForeignKey(a => a.CurrencyId);

            /******************************************************************
            /* Properties
            /*****************************************************************/
            Property(a => a.CashTransactionId)
                .IsRequired()
                .HasColumnName("ctx_id");

            Property(a => a.ManagedProductId)
                .IsRequired()
                .HasColumnName("ctx_mpd_id");

            Property(a => a.TransactionDate)
                .IsRequired()
                .HasColumnName("ctx_ts");

            Property(a => a.Amount)
                .IsRequired()
                .HasPrecision(18, 6)
                .HasColumnName("ctx_amount");

            Property(a => a.CurrencyId)
                .IsRequired()
                .HasColumnName("ctx_cur_id");

            Property(a => a.AmountRefCurrency)
                .IsRequired()
                .HasPrecision(18, 6)
                .HasColumnName("ctx_ref_cur_amt");
        }
    }
}
